package com.chenyi.web.controller.shop;

import java.util.List;

import com.chenyi.common.annotation.UserRequired;
import com.chenyi.common.enums.OperatorType;
import com.chenyi.common.utils.ShopUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import com.chenyi.common.annotation.Log;
import com.chenyi.common.core.controller.BaseController;
import com.chenyi.common.enums.BusinessType;
import com.chenyi.shop.domain.SysShopRole;
import com.chenyi.shop.service.ISysShopRoleService;
import com.chenyi.common.utils.poi.ExcelUtil;
import com.chenyi.common.core.page.TableDataInfo;

/**
 * 商户角色信息Controller
 * 
 * @author chenyi
 * @date 2020-10-26
 */
@RestController
@RequestMapping("/shop/role")
public class ShopRoleController extends BaseController
{
    @Autowired
    private ISysShopRoleService sysShopRoleService;

    /**
     * 查询商户角色信息列表
     */
    @UserRequired
    @GetMapping("/list")
    public ResponseEntity<TableDataInfo> list(SysShopRole sysShopRole)
    {
        startPage();
        List<SysShopRole> list = sysShopRoleService.selectSysShopRoleList(sysShopRole);
        return new ResponseEntity<>(getDataTable(list),HttpStatus.OK);
    }

    /**
     * 导出商户角色信息列表
     */
    @UserRequired
    @Log(title = "商户角色信息", businessType = BusinessType.EXPORT,operatorType = OperatorType.SHOP)
    @GetMapping("/export")
    public ResponseEntity<Object> export(SysShopRole sysShopRole)
    {
        List<SysShopRole> list = sysShopRoleService.selectSysShopRoleList(sysShopRole);
        ExcelUtil<SysShopRole> util = new ExcelUtil<SysShopRole>(SysShopRole.class);
        return util.exportExcel(list, "role");
    }

    /**
     * 获取商户角色信息详细信息
     */
    @UserRequired
    @GetMapping(value = "/{roleId}")
    public ResponseEntity<Object> getInfo(@PathVariable("roleId") Long roleId)
    {
        return ResponseEntity.ok(sysShopRoleService.selectSysShopRoleById(roleId));
    }

    /**
     * 新增商户角色信息
     */
    @UserRequired
    @Log(title = "商户角色信息", businessType = BusinessType.INSERT,operatorType = OperatorType.SHOP)
    @PostMapping
    public ResponseEntity<Object> add(@RequestBody SysShopRole sysShopRole)
    {
        sysShopRole.setShopId(ShopUtils.getShopId());
        sysShopRoleService.insertSysShopRole(sysShopRole);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    /**
     * 修改商户角色信息
     */
    @UserRequired
    @Log(title = "商户角色信息", businessType = BusinessType.UPDATE,operatorType = OperatorType.SHOP)
    @PutMapping
    public ResponseEntity<Object> edit(@RequestBody SysShopRole sysShopRole)
    {
        sysShopRoleService.updateSysShopRole(sysShopRole);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    /**
     * 删除商户角色信息
     */
    @UserRequired
    @Log(title = "商户角色信息", businessType = BusinessType.DELETE,operatorType = OperatorType.SHOP)
	@DeleteMapping("/{roleIds}")
    public ResponseEntity<Object> remove(@PathVariable Long[] roleIds)
    {
        sysShopRoleService.deleteSysShopRoleByIds(roleIds);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
